﻿using MediatR;
using W.Device.API.Application.Command;
using W.Device.Repository.Interface;

namespace W.Device.API.Application.CommandHandlder
{
    public class DeviceIsdelAllcommandHandler : IRequestHandler<DeviceIsdelAllcommand, int>
    {
        private readonly IDeviceRepository deviceRepository;

        public DeviceIsdelAllcommandHandler(IDeviceRepository deviceRepository)
        {
            this.deviceRepository = deviceRepository;
        }

        public async Task<int> Handle(DeviceIsdelAllcommand request, CancellationToken cancellationToken)
        {
            var list = (await deviceRepository.GetAllAsaync()).Where(x => request.Ins.Contains(x.DeviceId)).ToList();
            list.ForEach(x =>
            {
                x.IsDelete = true;
                x.DeleteTime = DateTime.Now;
            });
            return await deviceRepository.UpdateAll(list);
        }
    }
}
